package com.heather.exam.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.heather.exam.mapper.UserMapper;
import com.heather.exam.pojo.table.User;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

    @Service
    public class UserService {
        @Resource
        private UserMapper userMapper;

        public User Login(String username,String password){
            // 使用MyBatis Plus的selectOne方法，封装查询条件为"username = #{username} AND password = #{password}"
            // 并返回查询结果
            return userMapper.selectOne(new QueryWrapper<User>().eq("username", username).eq("password", password));
        }

        public void Insert(String username,String password,int role){
            // 创建User对象，并设置用户名和密码
            User user = new User();
            user.setUsername(username);
            user.setPassword(password);
            user.setRoleId(user.getRoleId());
            user.setUser_status(user.getUser_status());
            // 使用MyBatis Plus的insert方法，将User对象插入到数据库中
            userMapper.insert(user);
        }
    }

